﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>MouseGetPos - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The MouseGetPos function retrieves the current position of the mouse cursor, and optionally which window and control it is hovering over." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>MouseGetPos</h1>

<p>Retrieves the current position of the mouse cursor, and optionally which window and control it is hovering over.</p>

<pre class="Syntax"><span class="func">MouseGetPos</span> <span class="optional">OutputVarX, OutputVarY, OutputVarWin, OutputVarControl, Flag</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>OutputVarX, OutputVarY</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#variables">变量</a></p>
    <p>The names of the variables in which to store the X and Y coordinates. The retrieved coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change to screen coordinates.</p>
  </dd>

  <dt>OutputVarWin</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#variables">变量</a></p>
    <p>This optional parameter is the name of the variable in which to store the <a href="../misc/WinTitle.htm#ahk_id">unique ID number</a> of the window under the mouse cursor. If the window cannot be determined, this variable  will be made blank.</p>
    <p>The window does not have to be active to be detected. Hidden windows cannot be detected.</p>
  </dd>

  <dt>OutputVarControl</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#variables">变量</a></p>
    <p>This optional parameter is the name of the variable in which to store the name (ClassNN) of the control under the mouse cursor.  If the control cannot be determined, this variable  will be made blank.</p>
    <p>The names of controls should always match those shown by the Window Spy. However, unlike Window Spy, the window under the mouse cursor does not have to be active for a control to be detected.</p>
  </dd>

  <dt>Flag</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>If omitted or 0, the function uses the default method to determine <em>OutputVarControl</em> and stores the control's ClassNN. To change this behavior, add up one or both of the following digits:</p>
    <p><strong>1</strong>: Uses a simpler method to determine <em>OutputVarControl</em>. This method correctly retrieves the active/topmost child window of an Multiple Document Interface (MDI) application such as SysEdit or TextPad. However, it is less accurate for other purposes such as detecting controls inside a GroupBox control.</p>
    <p><strong>2</strong>: Stores the <a href="ControlGetHwnd.htm">control's HWND</a> in <em>OutputVarControl</em> rather than the <a href="ControlGetClassNN.htm">control's ClassNN</a>.</p>
    <p>例如, to put both options into effect, the <em>Flag</em> parameter must be set to 3.</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>Any of the output variables may be omitted if the corresponding information is not needed.</p>
<h2 id="Related">相关</h2>
<p><a href="CoordMode.htm">CoordMode</a>, <a href="Win.htm">Win functions</a>, <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>, <a href="Click.htm">Click</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>MouseGetPos xpos, ypos 
MsgBox "The cursor is at X" xpos " Y" ypos</pre>
</div>

<div class="ex" id="ExWatchCursor">
; the title of the window currently under the cursor:</em>	<p><a href="#ExWatchCursor">#2</a>: This example allows you to move the mouse around to see the title of the window currently under the cursor:</p>
<pre>SetTimer "WatchCursor", 100

WatchCursor()
{
    MouseGetPos , , id, control
    ToolTip
    (
        "ahk_id " id "
        ahk_class " WinGetClass("ahk_id " id) "
        " WinGetTitle("ahk_id " id) "
        Control: " control
    )
}</pre>
</div>

</body>
</html>